def singleton(cls):
    instances = {}
    def getinstance():
        if cls not in instances:
            instances[cls] = cls()
        return instances[cls]
    return getinstance


@singleton
class IpGen():
    def __init__(self, pre=12):
        self.pre = pre
        self.m = 0
        self.n = 0
        self.m1 = 0
        self.n1 = 0

    def gen(self):
        ip1 = '%s.%s.%s.1/24' % (self.pre, self.m, self.n)
        ip2 = '%s.%s.%s.2/24' % (self.pre, self.m, self.n)
        self.n += 1
        if self.n == 256:
            self.m += 1
            self.n = 0
        return (ip1, ip2)

    def genHIP(self):
        ip1 = '13.%s.%s.1/24' % (self.m, self.n)
        ip2 = '13.%s.%s.2/24' % (self.m, self.n)
        self.n += 1
        if self.n == 256:
            self.m += 1
            self.n = 0
        return (ip1, ip2)

    def genCIP(self):
        ip1 = '11.%s.%s.1/8' % (self.m1, self.n1)
        self.n1 += 1
        if self.n1 == 256:
            self.m1 += 1
            self.n1 = 0
        return ip1